package com.rjpacket.chileme.app.models;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by aaa on 15-3-22.
 */
public class Store implements Serializable {
    private int deliver_spent;               // 37,
    private boolean is_favored;                  // false,
    private int coupon_enabled;              // 0,
    private int invoice;                     // 0,
    private int id;                          // 155996,
    private int bookable;                    // 1,
    private String flavors;                     // "中式",
    private int num_rating_2;                // 0,
    private List<Icon> icons;                       // [],
    private int online_payment;              // 1,
    private double latitude;                    // 40.035838,
    private String tips;                        // "月售505份 12元起送 37分钟",
    private String activities;                  // "1",
    private long upcoming_serving_time;       // 1426925434,
    private String description;                 // "一锅香过桥米线是一家正宗的云南过桥米线,好吃,健康.",
    private String promotion_info;              // "",
    private String phone;                       // "18211125807",
    private int recent_food_popularity;      // 505,
    private String address;                     // "海淀区清河宝盛里小区2#底商",
    private int num_rating_1;                // 1,
    private int num_rating_3;                // 3,
    private String status_description;          // "餐厅营业中","接受预定中"
    private int num_rating_5;                // 24,
    private int num_rating_4;                // 9,
    private String distance;                    // "0.12km",
    private int min_deliver_amount;          // 12,
    private String name;                        // "一锅香过桥米线+黄焖鸡米饭",
    private int invoice_min_amount;          // 0,
    private int is_brand;                    // 0,
    private double longitude;                   // 116.370835,
    private String image_url;                   // "http://fuss10.elemecdn.com/8/12/f2d28c0c23e856025b2dd4ebddd0djpeg.jpeg?w=86&h=86",
    private String business_hour;               // "10:00:00-22:00:00",
    private int recent_order_number;         // 244,
    private boolean is_bookable;                 // true,
    private int busy_level;                  // 1,
    private int agent_fee;                   // 0

    public void parseJson(JSONObject json) {
        icons = new LinkedList<Icon>();
        try {
            deliver_spent = json.getInt("deliver_spent");
            is_favored = json.getBoolean("is_favored");
            coupon_enabled = json.getInt("coupon_enabled");
            invoice = json.getInt("invoice");
            id = json.getInt("id");
            bookable = json.getInt("bookable");
            flavors = json.getString("flavors");
            num_rating_2 = json.getInt("num_rating_2");
//            icons = json.getInt("icons");
            /////解析icon
            JSONArray array = json.getJSONArray("icons");
            int length = array.length();
            for (int i = 0; i < length; i++) {
                JSONObject iconJSON = array.getJSONObject(i);
                Icon icon = new Icon();
                icon.parseJSON(iconJSON);
                icons.add(icon);
            }
            /////
            online_payment = json.getInt("online_payment");
            latitude = json.getDouble("latitude");
            tips = json.getString("tips");
            activities = json.getString("activities");
            upcoming_serving_time = json.getInt("upcoming_serving_time");
            description = json.getString("description");
            promotion_info = json.getString("promotion_info");
            phone = json.getString("phone");
            recent_food_popularity = json.getInt("recent_food_popularity");
            address = json.getString("address");
            num_rating_1 = json.getInt("num_rating_1");
            num_rating_3 = json.getInt("num_rating_3");
            status_description = json.getString("status_description");
            num_rating_5 = json.getInt("num_rating_5");
            num_rating_4 = json.getInt("num_rating_4");
            distance = json.getString("distance");
            min_deliver_amount = json.getInt("min_deliver_amount");
            name = json.getString("name");
            invoice_min_amount = json.getInt("invoice_min_amount");
            is_brand = json.getInt("is_brand");
            longitude = json.getDouble("longitude");
            image_url = json.getString("image_url");
            business_hour = json.getString("business_hour");
            recent_order_number = json.getInt("recent_order_number");
            is_bookable = json.getBoolean("is_bookable");
            busy_level = json.getInt("busy_level");
            agent_fee = json.getInt("agent_fee");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
